﻿using System.Reflection;
using System.Windows.Forms;

namespace SyringeControl.AssemblySelectors
{
    /// <summary>
    /// Implementation of <see cref="SyringeControl.IAssemblySelector"/> selecting assembly via dialog window
    /// </summary>
    class OpenFileAssemblySelector : IAssemblySelector
    {
        readonly OpenFileDialog _fileDialog;
        /// <summary>
        /// Initializes an instance of <see cref="OpenFileAssemblySelector"/>
        /// </summary>
        public OpenFileAssemblySelector()
        {
            _fileDialog = new OpenFileDialog { Multiselect = false, Filter = "|*.dll||*.exe" };
        }

        #region Члены IAssemblySelector
        /// <summary>
        /// Selects <see cref="System.Reflection.Assembly"/>
        /// </summary>
        /// <returns>selected assembly</returns>
        public Assembly SelectAssembly()
        {
            if (_fileDialog.ShowDialog() == DialogResult.OK)
                return new PathAssemblySelector(_fileDialog.FileName).SelectAssembly();
            return null;
        }

        #endregion
    }
}
